package com.text;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class Conn {
    public static void main(String[] args) {
        Connection con;
        //jdbc
        String driver="com.mysql.cj.jdbc.Driver";

        String url="jdbc:mysql://localhost:3306/mysql1";
        String user="root";
        String password="123456";
        try {
                     Class.forName(driver);
                   con = DriverManager.getConnection(url, user, password);
            String sql="select * from user";
            Statement statement = con.createStatement();
            ResultSet resultSet = statement.executeQuery(sql);
            while (resultSet.next()){

                System.out.println(resultSet.getString("username"));
                System.out.println(resultSet.getString("password"));
            }

            if (!con.isClosed()) {
//           System.out.println("连接失败");
            }
            con.close();
        } catch (ClassNotFoundException e) {
            //System.out.println("װ");

        } catch (SQLException e) {
            e.printStackTrace();
            //System.out.println("���ݿ�����ʧ��");
        }
    }
}

